#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>

#define N 9

int pos[N];

enum colours {
	PURPLE,
	RED,
	WHITE,
	BROWN,
	YELLOW,
	GREEN,
	ORANGE,
	BLUE,
	PINK
};

const int board[N][N] = {
	{ PURPLE, PURPLE, PURPLE, PURPLE, PURPLE, PURPLE, PURPLE, PURPLE, PURPLE },
	{ PURPLE, PURPLE, RED,    BROWN,  BROWN,  BROWN,  PINK,   PINK,   PINK   },
	{ PURPLE, RED,    RED,    WHITE,  BROWN,  PINK,   PINK,   PINK,   PINK   },
	{ PURPLE, RED,    WHITE,  WHITE,  BROWN,  ORANGE, ORANGE, PINK,   PINK   },
	{ PURPLE, RED,    WHITE,  YELLOW, YELLOW, YELLOW, ORANGE, ORANGE, PINK   },
	{ PURPLE, RED,    WHITE,  WHITE,  YELLOW, ORANGE, ORANGE, PINK,   PINK   },
	{ PURPLE, RED,    RED,    WHITE,  YELLOW, ORANGE, BLUE,   PINK,   PINK   },
	{ PURPLE, RED,    RED,    GREEN,  GREEN,  GREEN,  BLUE,   BLUE,   PINK   },
	{ PURPLE, PURPLE, RED,    RED,    GREEN,  BLUE,   BLUE,   PINK,   PINK   }
};

void
print(void)
{
	for (int i = 0; i < N - 1; i++) {
		printf("%d ", pos[i]);
	}
	printf("%d\n", pos[N - 1]);
}

bool
check(int k)
{
	if (k >= 1) {
		if (abs(pos[k] - pos[k - 1]) <= 1) {
			return false;
		}
	}

	for (int i = 0; i < k; i++) {
		if (pos[i] == pos[k]) {
			return false;
		}
		// This ain't even the original problem anymore
		//if (abs(pos[i] - pos[k]) == k - i) {
		//	return false;
		//}
		//if (board[i * N + pos[i]] == board[k * N + pos[k]]) {
		if (board[i][pos[i]] == board[k][pos[k]]) {
			return false;
		}
	}

	return true;
}

int
solve(int k)
{
	int sum = 0;

	if (k >= N) {
		print();
		return 1;
	}

	for (int i = 0; i < N; i++) {
		pos[k] = i;
		if (!check(k)) {
			continue;
		}
		sum += solve(k + 1);
	}

	return sum;
}

int
main(void)
{
	int res;

	res = solve(0);
	printf("unique solutions: %d\n", res);

	return 0;
}
